import 'dart:io';

import 'package:path_provider/path_provider.dart';

import 'log_util.dart';

Future<String> _getUid() async {
  String uid = '';
  if(Platform.isIOS){
    Directory? documentsDir = await getApplicationDocumentsDirectory();
    List<String> tmp = documentsDir.path.split('/');
    Log.d('getUid:$tmp, length:${tmp.length}');

    return tmp[tmp.length - 2];
  }
  return uid;
}

Future<String> replaceUid(String path) async{
  if(path.isEmpty){
    return path;
  }
  if(!Platform.isIOS){
    return path;
  }
  Log.d('oldPath:$path');
  List<String> list = path.split('/');
  List<String> startList =  list.sublist(0, 6);
  String uid = await _getUid();
  List<String> endList = list.sublist(7, list.length);
  String newPath = '${startList.join('/')}/$uid/${endList.join('/')}';

  Log.d('newPath:$newPath');
  return newPath;
}